/**
 * 项目管理项目的公共处理方法。
 * 
 * @author TonyTan
 * @version 1.0, 2010-10-01
 */
JxPm = {};

(function(){

	Ext.apply(JxPm, {
		showAttach: function(data, funid, keyid) {
			/*if (data.ids == null || data.ids.length == 0) {
				JxHint.alert('该项目没有相关附件！');	
				return false;
			}*/
			//过滤条件
			var where_sql = '(fun_id = ? and data_id = ?)';
			if (data.ids.length > 0) {
				where_sql += ' or (sys_attach.attach_id in ('+ data.ids +'))';
			}
			var where_type = 'string;string';
			var where_value = funid+';'+keyid;
			
			//加载数据
			var hdcall = function(grid) {
				JxUtil.delay(500, function(){
					//设置目标功能信息
					grid.attachDataId = keyid;
					grid.attachFunId = funid;
					grid.attachAudit = '1';
					//删除GRID的自定义参数
					grid.on('beforedestroy', function(gp){
						gp.attachDataId = null;		delete gp.attachDataId;
						gp.attachFunId = null;		delete gp.attachFunId;
						gp.attachAudit = null;		delete gp.attachAudit;
						gp = null;
						return true;
					});
				
					Jxstar.loadData(grid, {where_sql:where_sql, where_value:where_value, where_type:where_type});
				});
			};

			var srcDefine = Jxstar.findNode('project_attach');
			//显示数据
			Jxstar.showData({
				filename: srcDefine.gridpage,
				title: '项目相关附件', 
				pagetype: 'grid',
				nodedefine: srcDefine,
				callback: hdcall
			});
		},
	
		//"今年剩余月份预计付款(万元)"调整后，需要修改其它金额值
		calPlanMoney: function(record) {
			//截止上年底累计付款(万元)
			var sun_money1 = record.getNum('money_plan__sun_money1');
			//今年截止统计月份实际付款(万元)
			var tran_money1 = record.getNum('money_plan__tran_money1');
			//今年剩余月份预计付款(万元)，这个值是手工填的
			var tran_money2 = record.getNum('money_plan__tran_money2');
			
			//======================计算公式====================
			//今年预计完成付款 = 今年截止统计月份实际付款 + 今年剩余月份预计付款
			var my_money_pay1 = tran_money1 + tran_money2;
			if (my_money_pay1 < 0) my_money_pay1 = 0;
			record.set('money_plan__money_pay1', my_money_pay1);
			
			//截止今年底累计付款额 = 截止上年底累计付款 + 今年预计完成付款
			var my_sun_money = sun_money1 + my_money_pay1;
			record.set('money_plan__sun_money', my_sun_money);
		},
		
		//显示国家局备案的子计划
		showSubPlan: function(parentId, subFunId, isturn, pfunId){
			//加载数据
			var hdcall = function(grid) {
				//显示数据
				JxUtil.delay(500, function(){
					//如果是国家局备案，则已结转的子计划不能增减子计划
					if (pfunId.indexOf('money_memo') >= 0 && isturn == '1') {
						JxUtil.getButton(grid.getTopToolbar(), 'delsub').disable();
						JxUtil.getButton(grid.getTopToolbar(), 'dataimp').disable();
					}
					if (pfunId.indexOf('money_query') >= 0 || pfunId.indexOf('money_auth') >= 0 || 
						pfunId.indexOf('money_daplan') >= 0) {
						JxUtil.disableButton(grid.getTopToolbar(), true);
					}
				
					//设置外键值
					grid.fkValue = parentId;
					//设置下面两个值是用于处理修改子计划的金额信息时，自动汇总父计划的金额并刷新显示
					grid.tmpParentId = parentId;
					grid.tmpParentFunId = pfunId;
					Jxstar.loadData(grid, {where_sql:'plan_parentid=?', where_value:parentId, where_type:'string'});
				});
			};

			//显示数据
			var define = Jxstar.findNode(subFunId);
			Jxstar.showData({
				filename: define.gridpage,
				title: define.nodetitle,
				pagetype: 'subgrid',
				width: 950,
				height: 300,
				nodedefine: define,
				callback: hdcall
			});
		}
		
	});//Ext.apply

})();
